package com.wzl.customviewproject.util;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.wzl.customviewproject.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：longxiansen
 * 功能：
 */
public class OnClickFlowLayout extends FlowLayout{
    public OnClickFlowLayout(Context context) {
        super(context);
    }

    public OnClickFlowLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public OnClickFlowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private static List<String> datas = new ArrayList<>();

    public void setData(List<String> datas){
        for (int i = 0; i < datas.size(); i++) {
            String content = datas.get(i);
            TextView textView = new TextView(getContext());
            textView.setText(content);
            textView.setPadding(dp2px(10),dp2px(5),dp2px(10),dp2px(5));
            textView.setBackgroundResource(R.drawable.bg_yellow);
            textView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getContext(), content, Toast.LENGTH_SHORT).show();
                }
            });
            addView(textView);
        }
        postInvalidate();
    }
}
